package com.wave.spring.web.controller;

import jmind.base.util.RandUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 基于SSE（server send event服务端发送事件）的服务器推送
 * 需要服务器支持event-stream
 * 浏览器支持 EventSource的sse 。Firefox，chrome 都支持
 */
@Controller
public class SseController {
    @RequestMapping(value ="push",produces = "text/event-stream")
    public @ResponseBody String push(){
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
       return "data:Testing 1,2,3..."+ RandUtil.randomCode(10);
    }
}
